/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.bsly.modules.app.service.localmaster.impl;


import com.google.code.kaptcha.Producer;
import io.bsly.common.exception.RRException;
import io.bsly.common.utils.RedisTools;
import io.bsly.modules.app.service.localmaster.SysCaptchaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;
/**
 * 验证码
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service("sysCaptchaService")
public class SysCaptchaServiceImpl  implements SysCaptchaService {
    @Autowired
    private Producer producer;

    @Autowired
    RedisTools redisTools;

    @Override
    public BufferedImage getCaptcha(String uuid) {
        if(StringUtils.isBlank(uuid)){
            throw new RRException("uuid不能为空");
        }
        //生成文字验证码
        String code = producer.createText();

        redisTools.set("user:login:captcha:"+uuid,code,60);
        return producer.createImage(code);
    }


}
